﻿////Javascript Object Dictionary Object
function jsObjectDictionary()
{
	//key array
	this.keys = new Array();
	
	//value array
	this.values = new Array();

	//the number of key value pairs currently in here
	this.count = 0;
	
	//adds key,value pair
	jsObjectDictionary.prototype.add = _od_Add;
	
	//removes key,value pair
	jsObjectDictionary.prototype.remove = _od_Remove;
	
	//removes all pairs
	jsObjectDictionary.prototype.removeAll = _od_RemoveAll;
	
	//gets a value from a key
	jsObjectDictionary.prototype.getVal = _od_GetVal;
	
	//sets a value from an existing key
	jsObjectDictionary.prototype.setVal = _od_SetVal;		
	
	//checks if the dictionary contains a key
	jsObjectDictionary.prototype.containsKey = _od_ContainsKey;
}

//add key value pair
function _od_Add(_key,obj)
{	
	//if the key already exists, set its new value
	if(this.containsKey(_key)!=-1)
	{
		this.setVal(_key);
		return false;
	}
	//if the key doesnt exist, add it
	this.keys.push(_key);
	this.values.push(obj);
	this.count++;
	return true;
}

//remove key/value
function _od_Remove(_key)
{
	var loc = this.containsKey(key);
	//make sure there is something to remove
	if(loc==-1)
		return false;
	//remove it
	this.keys.splice(loc,1);
	this.values.splace(loc,1);
	this.count--;
}


//remove all keys and values
function _od_RemoveAll()
{
	this.keys = [];
	this.values = [];
	this.count=0;
}

//get a value
function _od_GetVal(_key)
{
	//find it
	for(var ia = 0;ia<this.keys.length;ia++)
	{
		if(_key == this.keys[ia])
		{
			//return it
			return this.values[ia];
		}
	}
}

//set a value
function _od_SetVal(_key,_val)
{
	var loc = this.containsKey(_key);
	//if it doesnt already exist... add it
	if(loc!=-1)
		this.values[loc]=_val;
	else
		this.add(_key,_val);
}

//check if a key already exists
function _od_ContainsKey(_key)
{
	//at first the key doesnt exist
	var bContains = false;
	for(var ia = 0;ia<this.keys.length;ia++)
	{
		if(_key == this.keys[ia])
		{
			//return the location if found
			return ia;
		}
	}
	//return -1 if never found
	return -1;
}